
#include <physm.h>

static long _physm_body_next_id = 0;

void physm_body_init(physm_body_t *body){

  memset(body, 0, sizeof(physm_body_t));
  body->id = _physm_body_next_id++;
  pthread_mutex_init(&body->lock, NULL);

}

pthread_mutex_t _physm_print_lock;
int _physm_print_lock_init = 0;

void _physm_body_print(physm_body_t *body){

  if (_physm_print_lock_init == 0){
    pthread_mutex_init(&_physm_print_lock, NULL);
  }

  pthread_mutex_lock(&_physm_print_lock);
  fprintf(stderr, "Body: ID=%ld\n  Loc:   ", body->id);
  vm_fprintln(stderr, body->loc);
  fprintf(stderr, "  Vel:   ");
  vm_fprintln(stderr, body->vel);
  fprintf(stderr, "  Force: ");
  vm_fprintln(stderr, body->force);
  fprintf(stderr, "  Accel: ");
  vm_fprintln(stderr, body->accel);
  fprintf(stderr, "  Width=%lf Mass=%lf\n", body->width, body->mass);
  pthread_mutex_unlock(&_physm_print_lock);

}
